#include "semi/util/SocketUtil.h"

using namespace semi;
using namespace semi::util;

void receive() {

    SocketUtil su(1300);
    std::cout << "tcpListen" << std::endl;
    bool bl = su.tcpListen(3);

    if (!bl)
        std::cout << "tcpListen false" << std::endl;

    while (bl) {
        std::string ret = su.tcpReceive();
        std::cout << " tcpReceive " << ret << std::endl;
        sleep(1);
    }

    su.end();
}

void send() {

    SocketUtil su("localhost", 1300);
    //    SocketUtil su("127.0.0.1", 1300);
    //    SocketUtil su("192.168.1.129", 1300);
    bool bl = su.tcpConnect(5);
    if (bl)
        bl
                = su.tcpSend(
                        "message test0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
                        15);

    if (!bl)
        std::cout << "tcpSend false" << std::endl;

}

int main() {

    //    receive();
    send();

    return 0;
}
